package com.yuanthink.commons.base;

import java.io.Serializable;
import java.util.List;

import org.springframework.transaction.annotation.Transactional;
/**
 * 
 * @author 06peng
 *
 * @param <E>
 * @param <PK>
 */
public abstract class BaseEntityManager<E, PK extends Serializable> {

	protected abstract EntityDao<E,PK> getEntityDao();
	
	@Transactional(readOnly=true) 
	public E getById(PK id) {
		return getEntityDao().getById(id);
	}
	
	@Transactional(readOnly=true)
	public List<E> findAll() {
		return getEntityDao().findAll();
	}
	
	@Transactional(readOnly=true)
	public List<E> search(String sql) {
		return getEntityDao().search(sql);
	}
	
	@Transactional
	public void saveOrUpdate(E entity) {
		getEntityDao().saveOrUpdate(entity);
	}
	
	@Transactional
	public void save(E entity) {
		getEntityDao().save(entity);
	}
	
	@Transactional
	public void deleteById(PK id) {
		getEntityDao().deleteById(id);
	}

    @Transactional
	public void delete(E obj) {
        if(obj!=null){
            getEntityDao().delete(obj);
        }
	}
	
	@Transactional
	public void update(E entity) {
		getEntityDao().update(entity);
	}
	
	@Transactional
	public void executeSQL(String sql) {
		getEntityDao().executeSQL(sql);
	}
}
